#ifndef _Epoll_Accept_H
#define	_Epoll_Accept_H

#include <sys/epoll.h>
#include <arpa/inet.h>
// IPC
#include "../../ipc/mmap/MMAP_IO.cpp"
// base class
#include "../base/Server_Base.h"


enum EVENTS
{
    EPOLL_READ = 0x001,
    EPOLL_WRITE = 0x002,
    EPOLL_ACCEPT = 0x003,
    EPOLL_ERROR = 0x004
};

/**
 *  config info
 */
struct Epoll_Accept_Conf {
    // max listen fd num
    int m_nMax_epollfd_size;
    // max trigger info size
    int m_nMax_info_size;
    // server's event
    struct epoll_event m_sServerEvent;
    // epoll fd
    int m_nEpollfd;
    // a switch of server
    int m_nOn_off;
    
    Epoll_Accept_Conf();
    
};

/**
 *  coming client's info
 */
struct Client_Info {
    struct sockaddr_in client_addr;
    socklen_t client_len;
    
    Client_Info();
};

/**
 *  accept one client, the result's format.
 */
struct Accept_Info
{
    int event;
    int client_fd;
    int server_fd;
    int epoll_fd;
    char* remark;
    char* data;
    
    Accept_Info();
};



class Epoll_Accept : public Server_Base {
    public:
        // construction
        Epoll_Accept(int aServerSocketfd);
        
        Epoll_Accept(struct Epoll_Accept_Conf aConf);
        
        // init epollfd and configure epoll
        int Configure();
        
        /**
         * Start Listen Port
         */
        int Listening();
        
        /**
         * IPC Part
         */
        int MMAP_OUT(struct Accept_Info* a_infoStruct);
        
        int init();
        
        
    
    private:
        // this epoll server's configure struct
        struct Epoll_Accept_Conf m_sConf;
        struct Client_Info* m_sClientInfos;
        MMAP_IO<Accept_Info>* m_pIPC_mmap;
        
};




#endif	/* _Epoll_Accept_H */